package cn.edu.swpu.cins.u_chain.frontend.controller.user;

import cn.edu.swpu.cins.u_chain.Exception.user.OtherException;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.other.OtherDetail;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.other.OtherInfo;
import cn.edu.swpu.cins.u_chain.frontend.service.user.OtherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

@RestController
@RequestMapping("UChain/user/other")
public class OtherController {

    @Autowired
    private OtherService otherService;

    //@ExceptionHandler({OtherException.class, SQLException.class, RuntimeException.class})
    public ResultData handleException(Exception e) {
        return new ResultData(false, e.getMessage());
    }

    @PostMapping("addInfo")
    public ResultData addOtherInfo(@RequestBody OtherInfo otherInfo) {
        otherService.addInfo(otherInfo);
        return new ResultData(true, "添加成功");
    }

    @GetMapping("getInfo")
    public ResultData getOtherInfo(@RequestParam int userId) {
        OtherDetail detail = otherService.selectOtherDetail(userId);
        return new ResultData(true, "个人用户资料", detail);
    }
}
